"""
ASGI config for chat_room project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""

import os

from channels.auth import AuthMiddlewareStack
from django.core.asgi import get_asgi_application
from channels.routing import ProtocolTypeRouter,URLRouter
from django.urls import re_path
from message import consumers
from . import routing


os.environ.setdefault('DJANGO SETTINGS MODULE','chat_room.settings')
# application get_asgi_application()

application = ProtocolTypeRouter({
    "http":get_asgi_application(),
    "websocket":AuthMiddlewareStack(  # 包裹WebSocket路由，注入用户信息
        URLRouter([
            re_path(r'room/(?P<group>\w+)/$',consumers.ChatConsumer.as_asgi()),
        ])
    )
})

# URLRouter(routing.websocket_urlpatterns),